<?php

namespace app\v1\model;

use think\Model;
use think\model\concern\SoftDelete;
use WXBizDataCrypt;

class User extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';

    /**
     * code 换 session_key
     * @param string $js_code
     * @return bool|\returns|string
     */
    public function getOpenId(string $js_code)
    {
        $appid = config('appid');
        $secret = config('app_secret');
        $grant_type = 'authorization_code';
        //获取session_key
        $res = http_request(config('code2session'),compact('appid','secret','js_code','grant_type'));
        return json_decode($res, true);
//        $encryptedData = $post['encrypted_data'];
//        $iv = $post['iv'];
//        $pc = new WXBizDataCrypt($appid, $sessionKey);
//        $errCode = $pc->decryptData($encryptedData, $iv, $data );
//
//        if ($errCode == 0) {
//            print($data . "\n");
//        } else {
//            print($errCode . "\n");
//        }
    }
}
